#include "ChainOfResponsibility.h"

void Handler::setHandler(Handler *handler)
{
    successor_ = handler;
}

void Handler::handleRequest()
{
    if (successor_ != nullptr)
    {
        successor_->handleRequest();
    }
}

bool ConcreteHandlerA::canHandle()
{
    return false;
}

void ConcreteHandlerA::handleRequest()
{
    if (canHandle())
    {
        std::cout << "Handled by Concrete Handler A" << std::endl;
    }
    else
    {
        std::cout << "Cannot be handled by Concrete Handler A" << std::endl;
        Handler::handleRequest();
    }
}

bool ConcreteHandlerB::canHandle()
{
    return true;
}

void ConcreteHandlerB::handleRequest()
{
    if (canHandle())
    {
        std::cout << "Handled by Concrete Handler B" << std::endl;
    }
    else
    {
        std::cout << "Cannot be handled by Concrete Handler B" << std::endl;
        Handler::handleRequest();
    }
}
